//
//(C) Copyright 2011 HongKong Airline.,Ltd. 
//
/**
 * commentDaoHibernate
 *
 * 项目名称:代购系统
 *
 * @author Mengxiangliang
 *
 * 功能描述:
 * 
 * 历史版本:2013-01-04 v1.0.0 Mengxiangliang  创建:
 * 
 */
package com.gamutsoft.amb.comment.dao.impl;

import java.util.List;
import java.util.Map;

import com.gamutsoft.amb.comment.dao.ICommentDao;
import com.gamutsoft.amb.comment.model.Comment;
import com.gamutsoft.amb.common.bean.QueryExample;
import com.gamutsoft.amb.common.dao.impl.GenericDaoHibernate;
import com.gamutsoft.amb.common.exception.BusinessException;

@SuppressWarnings("unchecked")
public class CommentDaoHibernate extends GenericDaoHibernate<Comment, Long> implements ICommentDao {
    
     public CommentDaoHibernate() {
		super(Comment.class);

	}
    
    /**
	 * 根据条件查询记录
	 * @author Mengxiangliang
	 * @param  QueryExample
	 * @return List<Map>
	 * @throws BusinessException
	 */
	@Override
	public List<Map> searchCommentList(QueryExample qe) throws BusinessException {
	
	    StringBuffer sb = new StringBuffer();
		sb.append("SELECT T.ID,T.TITLE,T.CONTENT,T.CREATE_TIME,T.PACKAGEINFO_ID,T.STATUS,T.ORDERINFO_ID FROM COMMENT T");
		//qe.addOrderBy("");
		return this.findByQueryExample(sb.toString(), qe);
		
	}

	/**
	 * 根据ID查询记录
	 * @author Mengxiangliang
	 * @param id
	 * @return
	 * @throws BusinessException
	 */
	@Override
	public Comment searchCommentById(Long id) throws BusinessException {
	
	  Comment domain = new Comment();
	   String hql = "from Comment where id=?";
	   List<Comment> list = this.getHibernateTemplate().find(hql, id);
	   if(list != null && list.size() >0){
		  domain = list.get(0);
	   }
	   return domain;
		
	}

	/**
	 * 删除记录
	 * @author Mengxiangliang
	 * @param id
	 * @throws BusinessException
	 */
	@Override
	public void deleteCommentById(Long id) throws BusinessException {
	
	 String hql ="delete from Comment where id=?";
	 this.getHibernateTemplate().bulkUpdate(hql, id);
	 
	}

	@Override
	public List<Map> searchCommentByWhere(QueryExample qe, Comment domains)
			throws BusinessException {
		 StringBuffer sb = new StringBuffer();
		 sb.append("select t.id,t.title,t.content,t.create_time,u.userName,u.person_Img,c.address  from comment t ");
		 sb.append("left join packageinfo p on p.id=t.packageInfo_id ");
		 sb.append("left join system_user u on u.id=p.user_id ");
		 sb.append("left join contact_person c on c.package_id=p.id ");
		 qe.addOrderBy(" t.create_time desc ");
		  return this.findByQueryExample(sb.toString(), qe);
	}
	
}